import * as ECharts from "echarts";
import { observable } from "mobx";
import { model, Model, prop, modelAction } from "mobx-keystone";

@model("tb/RootStore")
export class Store extends Model({}) {
  //;
  @observable
  chartOptions: ECharts.EChartsCoreOption[] = [];

  onInit() {
    // console.log("Init");
    // 初始化请求数据(Mock接口), 实际使用中直接从接口请求数据.

    fetch("./data.json")
      .then((res) => res.json())
      .then(({ data }) => {
        const [xData, serData] = data;

        this.chartOptions = [
          {
            xAxis: {
              type: "category",
              data: xData,
            },
            yAxis: {
              type: "value",
            },
            series: [
              {
                data: serData,
                type: "line",
              },
            ],
          },
        ];
      });
  }
}
